##						  ##
#       p0f db Monitor	   #
##						  ##

from sqlite3 import dbapi2 as sqlite

class monP0f:
    def __init__(self):
        self.name="p0f db Monitor"
        self.result=""
        self.type="INFO"
        self.ipbuffer=""
        #connectie opzetten
        self.conlite=sqlite.connect("/etc/p0f/db.db.db")
        self.cursorlite=self.conlite.cursor()
        
    def convert(self,n):	
	d=256*256*256
	q=[]
	while d > 0:
		m,n=divmod(n,d)
		q.append(str(m))
		d=d/256
	return ".".join(q)
    
    def check(self):
    	self.cursorlite.execute("select ip_addr,name from system order by sid desc limit 1;")
    	self.temp=self.cursorlite.fetchone()
    	if(self.temp[0]!=self.ipbuffer):
    		 self.result="IP: "+str(self.convert(self.temp[0]))+"\n OS: "+self.temp[1]
    		 self.ipbuffer=self.temp[0]
    		 return 1
    	else:
    		 return 0
    
        
